<template>
	<scroll-view scroll-y :style="{height: height}">
		<lj-layout>
			<view style="padding:40rpx; display: flex; flex-direction: column;gap: 50rpx;">
				<view class="item" style="padding: 40rpx;">
					<view v-if="user.phone" style="display: flex;align-items: center;">
						<view @click="onClickGoUserProfile">
							<uv-image v-if="user.avatarUrl" :src="user.avatarUrl" width="80px" height="80px"
								shape="circle"></uv-image>
							<view style="width: 80px;border-radius:80px;display: block;overflow:hidden;">
								<open-data type="userAvatarUrl"></open-data>
							</view>
						</view>
						<view style="margin-left: 20rpx;">
							<view v-if="user.username" style="color: #6e94c1;font-size: 56rpx;font-weight: bold;">
								{{user.username}}
							</view>
							<view v-else style="font-size: 56rpx;font-weight: bold;">
								<open-data type="userNickName"></open-data>
							</view>
							<view v-if='user.studentNum'>学号：{{user.studentNum }}</view>
						</view>
					</view>
					<view v-else style="display: flex;flex-direction: column;">
						<view style="width: 100rpx;">
							<uv-button text="注册" @getphonenumber="onClickGetPhoneNumber" open-type="getPhoneNumber"
								color="linear-gradient(to right, rgb(66, 83, 216), rgb(213, 51, 186))"></uv-button>
						</view>
						<view style="font-size: 20rpx;margin-top: 10rpx;">注册并完善信息将获得更好的体验</view>
					</view>
				</view>
				<view class="item">
					<uv-cell-group>
						<uv-cell @click="onClickGo('/pages_nbst/views/my/examhistory')"
							icon="/pages_nbst/static/images/my/my-icon-exam-log.png" title="我的考试记录" :isLink="true"
							:titleStyle="cellTitleStyle"></uv-cell>
						<uv-cell @click="onClickGo('/pages_nbst/views/my/wrongquestion')"
							icon="/pages_nbst/static/images/my/my-icon-wrong-question.png" title="我的错题" :isLink="true"
							:titleStyle="cellTitleStyle"></uv-cell>
						<uv-cell @click="onClickGo('/pages_nbst/views/my/favquestion')"
							icon="/pages_nbst/static/images/my/my-icon-fav-question.png" title="我的收藏" :isLink="true"
							:titleStyle="cellTitleStyle"></uv-cell>
						<uv-cell v-if="user.role === 3" @click="onClickGo('/pages_nbst/views/my/userlist')"
							icon="/pages_nbst/static/images/my/my-icon-calendar.png" title="我的学员列表" :isLink="true"
							:titleStyle="cellTitleStyle"></uv-cell>
						<!-- <uv-cell v-if="user.role === 3" icon="/pages_nbst/static/images/my/my-icon-setting.png"
							title="考试历史列表" :isLink="true" :titleStyle="cellTitleStyle"></uv-cell> -->
						<uv-cell v-if="user.role === 3" @click="onClickGo('/pages_nbst/views/my/wrongquestion1')"
							icon="/pages_nbst/static/images/my/my-icon-checked.png" title="错误率最高题目" :isLink="true"
							:titleStyle="cellTitleStyle"></uv-cell>
					</uv-cell-group>
				</view>
				<view class="item" style="padding: 40rpx 20rpx;">
					<uv-grid :border="false" align="center">
						<uv-grid-item>
							<image class="module3-img" mode="widthFix"
								src="/pages_nbst/static/images/my/my-icon-kfzx.png"></image>
							<text class="grid-text">客服咨询</text>
							<button style="position: absolute;top: 0;left: 0;height: 100%;width: 100%;opacity: 0;"
								open-type="contact">客服</button>
						</uv-grid-item>
						<uv-grid-item @click="onClickAboutMe">
							<image class="module3-img" mode="widthFix"
								src="/pages_nbst/static/images/my/my-icon-lyfk.png"></image>
							<!-- <text class="grid-text">留言反馈</text> -->
							<text class="grid-text">关于我们</text>
						</uv-grid-item>
						<uv-grid-item @click="onClickCallPhone">
							<image class="module3-img" mode="widthFix"
								src="/pages_nbst/static/images/my/my-icon-dhzx.png"></image>
							<text class="grid-text">电话咨询</text>
						</uv-grid-item>
					</uv-grid>
				</view>
			</view>
		</lj-layout>
	</scroll-view>
</template>

<script setup>
	import {
		ref,
		reactive,
		onMounted,
	} from 'vue'
	import {
		onLoad,
	} from "@dcloudio/uni-app"

	import LjLayout from "@/pages_nbst/components/lj-layout.vue"
	import {
		useUserStore
	} from '@/pages_nbst/store/user.js'
	import {
		updateUserPhone
	} from '@/pages_nbst/api/auth.js'

	const props = defineProps({
		height: String
	})
	onLoad((request) => {
		console.log('my onLoad', request);
	})

	let user = useUserStore()

	const _onShow = (query) => {
		uni.setNavigationBarTitle({
			title: '我的主页'
		});
		uni.setNavigationBarColor({
			frontColor: '#000000',
			backgroundColor: '#ffffff',
		})
		console.log("my _onShow...................", query);
	}

	const cellTitleStyle = 'margin-left: 10rpx'
	const title = "我的"

	const onClickGo = (url) => {
		if (url) {
			uni.navigateTo({
				url
			})
		}
	}

	const onClickAboutMe = () => {
		uni.showModal({
			title: '关于我们',
			showCancel: false,
			content: "\t江西易公教育咨询有限公司是一家集教学、科研以及图书出版、发行于一体的大型公职类考试培训企业，专注于教师招聘、教师资格证和公务员等公职类考试的考前辅导。\n\t易公教育秉承“服务至上，进取协作，务实高效，诚信办学”的理念，十多年来，已累计帮助数万人实现了教师或公务员的职业梦想。\n\t易公教育成立于2003年，十多年的发展，已让易公教育成为省内外知名的专业化教育品牌企业。\n\t2013年易公教育强势入驻湖南、安徽两省，并在江西赣州、九江、上饶、景德镇、吉安等地市设立分校。\n\t易公教育以社会责任为己任，视教学效果为生命，已经形成了一支覆盖省内外知名高校和党政机构的权威师资团队。科学的教学体系，独特的教学模式，完善的教学服务，专业的管理团队，让易公教育引领着教师招聘等公职类考试辅导的发展方向。凭借强大的师资团队,一流的教学质量，真诚的学员服务，赢得了广大学员的一致好评。\n\t易公教育将与您一起开拓创新，进取协作，为实现您的人生理想不懈追求！",
			success: function(res) {}
		})
	}

	const onClickCallPhone = () => {
		uni.makePhoneCall({
			phoneNumber: '400-8585-820', //仅为示例
			success: function(res) {},
			fail: function(err) {}
		})
	}

	const onClickGetPhoneNumber = (e) => {
		console.log(e)
		if (e.errMsg === 'getPhoneNumber:ok') {
			updateUserPhone(e.code).then(res => {
				if (res.nb_user_id > 0) {
					user.setUser()
				} else {
					user.phone = res.phone
				}
			})
		}
	}

	const onClickGoUserProfile = () => {
		return
		uni.navigateTo({
			url: '/pages_nbst/views/my/userprofile'
		})
	}

	defineExpose({
		_onShow
	});
</script>

<style scoped lang="scss">
	.item {
		background-color: white;
		border-radius: 16rpx;
		box-shadow: 0 0 20rpx rgba(0, 0, 0, 0.1);
	}

	.module3-img {
		width: 70rpx;
		height: 70rpx;
		margin-bottom: 20rpx;
	}
</style>